package com.tool.tcpimg;

import org.come.Frame.ZhuFrame;
import org.come.Jpanel.FrameMessageChangeJpanel;
import org.come.control.TestMain;
import org.come.until.ScrenceUntil;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Component;
import org.come.Jpanel.TestSetupJpanel;
import org.come.Frame.TestSetupJframe;
import java.awt.Color;
import java.awt.Composite;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Graphics;
import java.util.ArrayList;
import org.come.until.CutButtonImage;
import org.come.bean.ImgZoom;
import javax.swing.ImageIcon;
import java.util.List;
import javax.swing.JPanel;

public class PetSkillBox extends JPanel
{
    private static final long serialVersionUID = 1L;
    private List<RichLabel> labels;
    private int deviation;
    private boolean Gag;
    private float Alpha;
    private boolean display;
    private int w;
    private int h;
    private String text;
    public static ImageIcon icon;
    private ImgZoom imgZoom;
    public final ImgZoom imgZoomS;

    public PetSkillBox() {
        this.deviation = 0;
        this.Gag = true;
        this.Alpha = 0.0f;
        this.display = false;
        this.w = 0;
        this.h = 0;
        this.imgZoom = CutButtonImage.cuts("inkImg/old/7/ss223.png", 14, 7, true);
        this.imgZoomS = CutButtonImage.cuts("inkImg/old/7/tishikuang.png", 14, 7, true);
        this.labels = new ArrayList();
        this.setBackground(UIUtils.Color_BACK);
    }

    @Override
    public void paint(final Graphics g) {
        if (this.labels.size() != 0) {
            final Graphics2D g2d = (Graphics2D)g.create();
            g2d.setComposite((Composite)AlphaComposite.getInstance(3, 1.0f));
            g2d.translate(0, 1);
            g2d.setColor(Color.BLACK);
            final TestSetupJpanel ss = TestSetupJframe.getTestSetupJframe().getTestSetupJpanel();

                this.imgZoomS.draw((Graphics)g2d);
                this.imgZoomS.setMiddlew(this.getWidth() - 2 * this.imgZoomS.getEdgew());
                this.imgZoomS.setMiddleh(this.getHeight() - 2 * this.imgZoomS.getEdgeh());

            int History = 0;
            int hig = -this.deviation * 22;
            g2d.translate(8, hig);
            int i = 0;
            while (i < this.labels.size()) {
                final Component c = (RichLabel)this.labels.get(i);
                g2d.translate(c.getX() - 2, History + 1);
                History = c.getHeight();
                hig += History;
                if (hig >= 0) {
                    c.paint((Graphics)g2d);
                    c.paint((Graphics)g2d);
                    c.paint((Graphics)g2d);
                }
                ++i;
            }
        }
    }

    public void addtext(final RichLabel label, final int size) {
        if (this.labels.size() > 100) {
            this.AddAndSubtract(2);
        }
        if (label != null) {
            this.labels.add(label);
        }
        this.Formsize(size);
        if (this.ScreenFull() != 0) {
            while (this.deviation < this.ScreenFull()) {
                ++this.deviation;
            }
        }
    }

    public void addtext(final String text, final int size, final Font font) {
        if (this.labels.size() > 100) {
            this.AddAndSubtract(2);
        }
        this.addText(text, size, font);
        if (this.ScreenFull() != 0) {
            while (this.deviation < this.ScreenFull()) {
                ++this.deviation;
            }
        }
    }

    public void addText(final String chatText, final int size) {
        final RichLabel label = new RichLabel(chatText, null);
        final Dimension d = label.computeSize(size);
        label.setSize(d);
        if (label != null) {
            this.labels.add(label);
        }
        this.add((Component)label);
        this.Formsize(size);
    }

    public RichLabel addText(final String chatText, final int size, final Font font) {
        final RichLabel label = new RichLabel(chatText, font);
        final Dimension d = label.computeSize(size);
        label.setSize(d);
        if (label != null) {
            this.labels.add(label);
        }
        this.Formsize(size);
        return label;
    }

    public RichLabel setText(final String text) {
        final RichLabel label = new RichLabel(text);
        this.text = text;
        label.sectionList.clear();
        return label;
    }

    public RichLabel removeAddText(final String chatText, final int size, final Font font) {
        this.removeAll();
        RichLabel label = (this.labels.size() != 0) ? ((RichLabel)this.labels.get(0)) : null;
        this.labels.clear();
        if (label == null) {
            label = new RichLabel(chatText, font);
            final Dimension d = label.computeSize(size);
            label.setSize(d);
        }
        else {
            label.setFont(font);
            label.setTextSize(chatText, size);
        }
        this.labels.add(label);
        this.Formsize(size);
        return label;
    }

    public void Formsize(final int size) {
        int h = 6;
        int i = 0;
        while (i < this.labels.size()) {
            h = (int)((double)h + ((RichLabel)this.labels.get(i)).getSize().getHeight());
            ++i;
        }
        this.setSize(size, h);
    }

    public void AddAndSubtract(final int type) {
        switch (type) {
            case 0: {
                if (this.ScreenFull() != 0 && this.deviation > 0) {
                    --this.deviation;
                    break;
                }
                else {
                    break;
                }
            }
            case 1: {
                if (this.ScreenFull() != 0 && this.deviation < this.ScreenFull()) {
                    ++this.deviation;
                    break;
                }
                else {
                    break;
                }
            }
            case 2: {
                this.removemsg();
                this.deviation = 0;
                this.Formsize(280);
                break;
            }
            case 3: {
                this.Gag = !this.Gag;
                break;
            }
            case 4: {
                this.RemoveForms();
                break;
            }
            case 5: {
                if (this.h < ScrenceUntil.Screen_y - 300) {
                    this.h += 20;
                    break;
                }
                else {
                    break;
                }
            }
            case 6: {
                if (this.h > 80) {
                    this.h -= 20;
                    break;
                }
                else {
                    break;
                }
            }
            case 7: {
                if (this.display) {
                    this.Alpha -= 0.2f;
                    if (this.Alpha <= 0.0f) {
                        this.Alpha = 0.6f;
                        break;
                    }
                    else {
                        break;
                    }
                }
                else {
                    break;
                }
            }
        }
    }

    public int ScreenFull() {
        int size = 0;
        int i = 0;
        while (i < this.labels.size()) {
            size = (int)((double)size + ((RichLabel)this.labels.get(i)).getSize().getHeight());
            ++i;
        }
        if (size - 22 >= this.h) {
            return (size - this.h) / 22 + 2;
        }
        else {
            return 0;
        }
    }

    public void RemoveForms() {
        if (!display) {
            Alpha = 0.6f;
            w = 300;
            h = 200;
            FrameMessageChangeJpanel.chatbox1.removemsg();
            FrameMessageChangeJpanel.chatbox2.removemsg();
            ZhuFrame.getzhuframe().getChangeJpanel().setVisible(false);// 让面板显示为不可见
            TestMain.gameJframe.setSize(ScrenceUntil.Screen_x + 6,
                    ScrenceUntil.Screen_y + 28);

//            ZhuFrame.getZhuJpanel().outForms();
        } else {
            FrameMessageChangeJpanel.chatbox.removemsg();
            Alpha = 0.0f;
            w = 300;
            h = ScrenceUntil.Screen_y / 2 - 20;
            ZhuFrame.getzhuframe().getChangeJpanel().setVisible(true);// 让面板显示为可见
            TestMain.gameJframe.setSize(ScrenceUntil.Screen_x
                    + ScrenceUntil.ChatFram_X + 6, ScrenceUntil.Screen_y + 28);

//            ZhuFrame.getZhuJpanel().intoForms();
        }
        display = !display;

    }

    public void removemsg() {
        this.removeAll();
        this.labels.clear();
    }

    public List<RichLabel> getLabels() {
        return this.labels;
    }

    public void setLabels(final List<RichLabel> labels) {
        this.labels = labels;
    }

    public int getDeviation() {
        return this.deviation;
    }

    public void setDeviation(final int deviation) {
        this.deviation = deviation;
    }

    public boolean isGag() {
        return this.Gag;
    }

    public void setGag(final boolean gag) {
        this.Gag = gag;
    }

    public float getAlpha() {
        return this.Alpha;
    }

    public void setAlpha(final float alpha) {
        this.Alpha = alpha;
    }

    public boolean isDisplay() {
        return this.display;
    }

    public void setDisplay(final boolean display) {
        this.display = display;
    }

    public int getW() {
        return this.w;
    }

    public void setW(final int w) {
        this.w = w;
    }

    public int getH() {
        return this.h;
    }

    public void setH(final int h) {
        this.h = h;
    }
}
